//
// Created by ✎﹏ℳ๓独赏 ☆独醉 on 2023/4/19.
//
#include <stdio.h>

//#include <stdlib.h>
int tmp[100];

void getdata(int arr[], int n) {
    int i;
    for (i = 0; i < n; i++) {
        arr[i] = n - i;
    }
}

void sort(int arr[], int l, int end01, int r, int end02) {
    int k = 0, start = l;
    while (l <= end01 && r <= end02) {
        if (arr[l] <= arr[r])tmp[k++] = arr[l++];
        else tmp[k++] = arr[r++];
    }
    while (l <= end01)tmp[k++] = arr[l++];
    while (r <= end02)tmp[k++] = arr[r++];
    for (int a = start, b = 0; a <= end02; a++, b++) {//此处一定要特别注意将转换数组赋值给原数组时下标起始位置值问题
        arr[a] = tmp[b];//由于上面的l自增，所以不能直接使用l为下标，需要借用一个标记记录l的初始值
    }
}

void fun(int q[], int l, int r) {
    if (l >= r) { return; }
    int mid = (l + r) / 2;
    fun(q, l, mid);
    fun(q, mid + 1, r);
    sort(q, l, mid, mid + 1, r);
}

int main() {
    int arr[50], i;
    getdata(arr, 50);
    for (i = 0; i < 50; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
    fun(arr, 0, 49);
    for (i = 0; i < 50; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
    for (i = 0; i <= 100; i++) {
        printf("%d ", tmp[i]);
    }
    return 0;
}